package com.thirtydays.frame.util

import android.graphics.Paint
import com.thirtydays.frame.util.ext.sp2pxFloat
import java.util.*

/**
 * @author 小垚
 * @创建时间： 2020/12/16
 * @描述：
 **/
object StringUtils {
    fun getRandomString(length: Int): String {
        var str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        val random = Random()
        val sb = StringBuffer()
        for (i in 0 until length) {
            val number = random.nextInt(62)
            sb.append(str[number])
        }
        return sb.toString()
    }

    /**
     * 计算字数宽度
     */
    fun measureText(content: String, size: Float = 18f): Float {
        val paint = Paint()
        paint.textSize = sp2pxFloat(size)
        return paint.measureText(content)
    }
}